﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--自适应界面,如果出现,在某些设备出现界面偏小的话,检查一下有没有加入这句 -->
    <meta http-equiv="Content-type" name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="../../../js/jqmobile/jquery.mobile-1.4.5.min.css" />
    <link href="../../../js/layer_mobile/need/layer.css" rel="stylesheet" />
    <link href="../../../layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <!--<script src="../js/jquery.js"></script>-->
    <script src="../../../js/jquery.min2.1.4.js"></script>
    <script src="../../../js/jqmobile/jquery.mobile-1.4.5.min.js"></script>
    <script src="../../../js/cordova-1.5.0.js"></script>
    <script src="../../../js/layer_mobile/layer.js"></script>
    <script src="../../../js/jshelp.js"></script>

    <script>
 
        //接受传参
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var customerCode = getUrlParam('customerCode');
        var mobile = getUrlParam('mobile');
        function tz(lx) {
            if (lx == "主页") {
                location.href = "..\\main.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "申请") {
                location.href = "..\\TransferRequest\\sq_list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "抢单") {
                location.href = "..\\TransferSnatch\\list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "发货") {
                location.href = "list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
            else if (lx == "配置") {
                location.href = "..\\Config\\list.html?mobile=" + mobile + "&customerCode=" + customerCode;
            }
        }
    </script>
    <style>
        ul {
            list-style-type: none;
            padding: 0px;
            margin: 0px;
        }

            ul li {
                background-image: url(sqpurple.gif);
                background-repeat: no-repeat;
                background-position: 0px 5px;
                padding-left: 14px;
            }

        .tck {
            font: normal 12px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
            color: #4f6b72;
            background: #E6EAE9;
            padding: 20px;
        }
        /*按钮*/
        .btn {
            display: block;
            position: relative;
            background: #aaa;
            padding: 10px 20px 10px 20px;
            float: left;
            color: #fff;
            text-decoration: none;
            cursor: pointer;
            font-size: 13px;
            margin: 5px;
        }

        /*数量加减*/
        * {
            margin: 0;
            padding: 0;
            border: 0;
            outline: 0
        }

        ul,
        li {
            list-style: none;
        }

        a {
            text-decoration: none;
        }

            a:hover {
                cursor: pointer;
                text-decoration: none;
            }

            a:link {
                text-decoration: none;
            }

        img {
            vertical-align: middle;
        }
        /*数量加减start*/
        .btn-numbox {
            overflow: hidden;
            margin-top: 20px;
        }

            .btn-numbox li {
                float: left;
            }

                .btn-numbox li .number,
                .kucun {
                    display: inline-block;
                    font-size: 12px;
                    color: #808080;
                    vertical-align: sub;
                }

            .btn-numbox .count {
                overflow: hidden;
                margin: 0 16px 0 -20px;
            }

                .btn-numbox .count .num-jian,
                .input-num,
                .num-jia {
                    display: inline-block;
                    width: 28px;
                    height: 28px;
                    line-height: 28px;
                    text-align: center;
                    font-size: 18px;
                    color: #999;
                    cursor: pointer;
                    border: 1px solid #e6e6e6;
                }

                .btn-numbox .count .input-num {
                    width: 58px;
                    height: 26px;
                    color: #333;
                    border-left: 0;
                    border-right: 0;
                }
        /*数量加减end*/
        .ui-listview > p {
            white-space: normal;
        }
        /*店铺名称单号行*/
        div#findstorename.ui-grid-a .ui-block-a {
            width: 55%
        }
        div#findstorename.ui-grid-a .ui-block-b {
            width: 45%
        }
        /*联系人联系方式行*/
        div#findlxr.ui-grid-a .ui-block-a {
            width: 50%
        }
        div#findlxr.ui-grid-a .ui-block-b {
            width: 50%
        }
        /*发布数量调拨数量日期行*/
        div#findsl.ui-grid-a .ui-block-a {
            width: 30%
        }
        div#findsl.ui-grid-a .ui-block-b {
            width: 30%
        }
        div#findsl.ui-grid-a .ui-block-c {
            width: 40%
        }
        /*发布货品行*/
        div#findhp.ui-grid-a .ui-block-a {
            width: 35%
        }
        div#findhp.ui-grid-a .ui-block-b {
            width: 35%
        }
        div#findhp.ui-grid-a .ui-block-c {
            width: 20%
        }
        div#findhp.ui-grid-a .ui-block-d {
            width: 10%
        }
        #controlgroupid .ui-controlgroup-controls {
            width: 100%;
        }

        #controlgroupid a {
            width: 25%;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div data-role="page" id="pageone">
        <div data-role="header" data-position="fixed">
            <h1>调拨发货</h1>
            <div data-role="navbar">
                <ul>
                    <li><a href="#" onclick="SnatchOrRequest('Snatch')">我的抢单</a></li>
                    <li><a href="#" onclick="SnatchOrRequest('Request')">我的申请</a></li>
                </ul>
            </div>
        </div>
        <div data-role="content" id="main3Content">
            <ul id="thelist" data-role="listview" data-split-icon="gear" data-split-theme="d"
                data-filter="true" data-inset="true" data-filter-placeholder="全局搜索"></ul>
        </div>
        <div data-role="footer" data-position="fixed">
            <div data-role="navbar">
                <ul id="navbarlist">
                    <li><a href="#" onclick="tz('主页')" data-role="button" data-icon="home" data-iconpos="top">首页</a></li>
                    <li><a href="#" onclick="tz('申请')" data-role="button" data-icon="plus" data-iconpos="top">调拨申请</a></li>
                    <li><a href="#" onclick="tz('抢单')" data-role="button" data-icon="shop" data-iconpos="top">调拨抢单</a></li>
                    <li><a href="#" onclick="tz('发货')" data-role="button" data-icon="navigation" data-iconpos="top">调拨发货</a></li>
                    <li><a href="#" onclick="tz('配置')" data-role="button" data-icon="gear" data-iconpos="top">设置</a></li>
                </ul>
            </div>
        </div>
    </div>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script>
        var clickCount = 1;
        // 引入form模块
        layui.use('form', function () {
            var form = layui.form;
            //加载快递公司
            //$.ajax({
            //    type: "post",
            //    url: "ashx/list.ashx?type=getkdgs",
            //    dataType: "json",
            //    success: function (data) {
            //        var html = '';
            //        if (data.data.length == 0) {
            //            html += "<option value=''>无数据</option>";
            //            $("#sel_kdgs").empty().append(html);
            //        } else {
            //            html += "<option value=''>请选择数据</option>";
            //            for (var i = 0; i < data.data.length; i++) {
            //                html += "<option value='" + data.data[i].id + "'>" + data.data[i].typename + "</option>"
            //            }
            //            $("#sel_kdgs").empty().append(html);
            //        }
            //        form.render('select');
            //    },
            //    error: function (data) {
            //        layer.error(data);
            //    }
            //});
        });
        function reinfo(docnos) {
            $.ajax({
                type: "post",
                async: true,
                url: 'ashx/list.ashx?type=get_reinfo&docnos=' + docnos,
                data: {},
                dataType: "json",
                success: function (res) {
                    if (res.flag == "True") {
                        layer.open({
                            title: '返回消息'
                            , content: res.remsg
                        });
                    }
                    else {
                        layer.msg(res.remsg);
                    }
                }
            })
        }
        function fahuo(docnos) {
            var htmls = '';
            htmls += '<div><input name="txt_kdgs" id="txt_kdgs" placeholder="快递公司" class="layui-input"></div>';
            htmls += '<div><input name="txt_name" id="txt_kddh" placeholder="快递单号" class="layui-input"></div>';
            htmls += '<div><input name="txt_kdfhr" id="txt_kdfhr" placeholder="发货人" class="layui-input"></div>';
            htmls += '<div><input name="txt_kdtel" id="txt_kdtel" placeholder="发货人联系电话" class="layui-input"></div>';
            layer.prompt({
                formType: 0,//这里依然指定类型是多行文本框，但是在下面content中也可绑定多行文本框
                title: '填写发货信息',
                area: ['200px', '300px'],
                btnAlign: 'c',
                content: htmls,
                yes: function (index, layero) {
                    var txt_kdgs = $('#txt_kdgs').val();//快递公司
                    var txt_kddh = $('#txt_kddh').val();//快递单号
                    var txt_kdfhr = $('#txt_kdfhr').val();//发货人
                    var txt_kdtel = $('#txt_kdtel').val();//发货人联系电话

                    if (txt_kdgs === "" || txt_kdgs === null || txt_kdgs === undefined) {
                        layer.msg('快递公司不能为空', { icon: 5 });
                        return false;
                    }
                    if (txt_kddh === "" || txt_kddh === null || txt_kddh === undefined) {
                        layer.msg('快递单号不能为空', { icon: 5 });
                        return false;
                    }
                    if (txt_kdfhr === "" || txt_kdfhr === null || txt_kdfhr === undefined) {
                        layer.msg('发货人不能为空', { icon: 5 });
                        return false;
                    }
                    if (txt_kdtel === "" || txt_kdtel === null || txt_kdtel === undefined) {
                        layer.msg('发货人联系电话不能为空', { icon: 5 });
                        return false;
                    }
                    //主体信息
                    var arrayObj_main = new Array();
                    var main = {
                        "docno": docnos,
                        "txt_kdgs": txt_kdgs,
                        "txt_kddh": txt_kddh,
                        "txt_kdfhr": txt_kdfhr,
                        "txt_kdtel": txt_kdtel
                    };
                    arrayObj_main.push(main);
                    var loginLoadIndex = layer.load(2);
                    //$('#loginBtn').val("正在登录...");
                    if (arrayObj_main.length > 0) {
                        //防止多次点击
                        if (clickCount >= 2) {
                            return false;
                        }
                        else {
                            $.ajax({
                                type: "post",
                                async: true,
                                url: 'ashx/list.ashx?type=save_fhinfo',
                                data: JSON.stringify({ 'ArrayObj_main': arrayObj_main }),
                                dataType: "json",
                                success: function (res) {
                                    debugger
                                    layer.close(loginLoadIndex);
                                    //var index = parent.layer.getFrameIndex(window.name);
                                    if (res.flag == "True") {
                                        debugger
                                        clickCount++;
                                        layer.msg(res.remsg, {
                                            time: 2000,
                                            end: function () {
                                                debugger
                                                parent.layer.close(index);
                                                location.reload();
                                                //window.location.href = "buylist.html";
                                                //<a href="buylist.html">buylist.html</a>
                                            }
                                        })
                                    }
                                    else {
                                        layer.msg(res.remsg);
                                        parent.layer.close(index);
                                        window.parent.location.reload();
                                    }
                                }
                            })
                        }
                    }

                }
            });
        }
       //获取发货申请列表
        function SnatchOrRequest(lxs) {
            var loginLoadIndex = layer.load(2);
            $.ajax({
                type: "get",
                async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                url: "ashx/list.ashx?type=get_deliver_list&lxs=" + lxs + "&customerCodes=" + customerCode + "&mobiles=" + mobile + "&a=" + Math.random(),
                data: {},
                dataType: "json",        //返回数据形式为json
                success: function (data) {
                    var str = "";
                    if (data.item.length > 0) {
                        for (var i = 0; i < data.item.length; i++) {
                            str += '<li>';
                            str += '<div id="findstorename" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<h3>调拨:' + data.item[i].buyusername + '</h3>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>单号：' + data.item[i].requestdocno + '</p>';
                            str += '</div>';
                            str += '</div>';
                            str += '<div class="ui-grid-a">';
                            str += '<p style="white-space:normal;">地址：' + data.item[i].takeaddress + '</p>';
                            str += '</div>';
                            str += '<div id="findlxr" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<p>联系人：' + data.item[i].takeman + '</p>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>联系方式：' + data.item[i].takephone + '</p>';
                            str += '</div>';
                            str += '</div>';
                            //str += '<div id="findhp" class="ui-grid-a">';
                            //str += '<div class="ui-block-a">';
                            //str += '<p>' + data.item[i].value + '</p>';
                            //str += '</div>';
                            //str += '<div class="ui-block-b">';
                            //str += '<p>' + data.item[i].name + '</p>';
                            //str += '</div>';
                            //str += '<div class="ui-block-c">';
                            //str += '<p>' + data.item[i].ys + '</p>';
                            //str += '</div>';
                            //str += '<div class="ui-block-d">';
                            //str += '<p>' + data.item[i].cmwm + '</p>';
                            //str += '</div>'
                            //str += '</div>';
                            str += '</li>';

                            str += '<li>';
                            str += '<div id="findstorename" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<h3>发货:' + data.item[i].saleusername + '</h3>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>单号：' + data.item[i].docno + '</p>';
                            str += '</div>';
                            str += '</div>';
                            str += '<div id="findlxr" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<p>快递公司：' + data.item[i].sale_kdgs + '</p>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>快递单号：' + data.item[i].sale_kddjbh + '</p>';
                            str += '</div>';
                            str += '</div>';
                            str += '<div id="findlxr" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<p>联系人：' + data.item[i].sale_kdlxr + '</p>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>联系电话：' + data.item[i].sale_kdtel + '</p>';
                            str += '</div>';
                            str += '</div>';
                            str += '<div id="findlxr" class="ui-grid-a">';
                            str += '<div class="ui-block-a">';
                            str += '<p>数量：' + data.item[i].sl + '</p>';
                            str += '</div>';
                            str += '<div class="ui-block-b">';
                            str += '<p>' + data.item[i].createtime + '</p>';
                            str += '</div>';
                            str += '</div>';
                            str += '</li>';
                            str += '<div data-role="navbar">';
                            str += '<ul>';
                            str += '<li><a href="#" data-transition="turn" onclick="productlist(\'' + data.item[i].docno + '\')">货品详情</a></li>';
                            if (lxs == "Request") {
                                if (data.item[i].zt == "待发货") {
                                    str += '<li><a style="color:white;background-color:crimson;" href="" >' + data.item[i].zt + '</a></li>';
                                }
                                else {
                                    str += '<li><a style="color:white;background-color:cadetblue;" href="#"  onclick="reinfo(\'' + data.item[i].docno + '\')">' + data.item[i].zt + '</a></li>';
                                }
                            } else {
                                if (data.item[i].zt == "待发货") {
                                    str += '<li><a style="color:white;background-color:crimson;" href="" onclick="judan(\'' + data.item[i].requestid + '\')">拒单</a></li>';

                                    str += '<li><a style="color:white;background-color:crimson;" href="" onclick="fahuo(\'' + data.item[i].docno + '\')">' + data.item[i].zt + '</a></li>';
                                }
                                else {
                                    str += '<li><a style="color:white;background-color:cadetblue;" href="#"  onclick="reinfo(\'' + data.item[i].docno + '\')">' + data.item[i].zt + '</a></li>';
                                }
                            }
                            str += '</ul>';
                            str += '</div>';
                        }
                    }
                    else {
                        str += '<li>';
                        str += '<h3 style="text-align:center;color:red;" >无数据</h3>';
                        str += '</li>';
                        ////提示
                        //layer.open({
                        //    content: "无数据!"
                        //    , skin: 'msg'
                        //    , time: 5 //2秒后自动关闭
                        //});
                    }
                    $("#thelist").html(str);
                    //解决列表样式丢失！
                    $("#thelist").trigger('create');
                    $("#thelist").listview("refresh");
                    layer.close(loginLoadIndex);
                }
            });
        }
        //拒单并重新发布
        function judan(ids) {
            debugger
            var loginLoadIndex = layer.load(2);
            layer.confirm('确定拒单吗？', function (index) {
                //执行 Ajax 后重载
                $.ajax({
                    url: 'ashx/list.ashx?type=againfabu&getids=' + ids,
                    type: "post",
                    contentType: "application/json",
                    dataType: "json",
                    data: {},
                    success: function (res) {
                        debugger
                        layer.close(loginLoadIndex);
                        if (res.flag == "True") {
                            layer.msg(res.remsg, {
                                time: 2000,
                                end: function () {
                                    location.reload();
                                    //location.href = "sq_list.html?customerCode=" + customerCode + "&mobile=" + mobile;;
                                }
                            })
                        }
                        else {
                            layer.alert(res.remsg);
                        }
                    }
                });
            });
        }
        function productlist(docnos) {
            location.href = "product_list.html?docno=" + docnos;
        }

        //加载商品列表
        $(function () {
            if (mobile == "" || mobile == undefined || mobile == null) {
            } else {
                SnatchOrRequest("Snatch");
            }
        });
    </script>

</body>
</html>
